package com.bootdo.system.dao;

import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.bootdo.system.domain.BabyDO;
import com.bootdo.system.domain.CourseTime;

public interface CourseTimeMapper {
	
	@Select("select * from tb_course_time where id=#{id}")
	CourseTime get(Long id);
	
	@Insert("INSERT INTO tb_course_time" + "(courseId, startTime,coursePoint,maxBabys,signedNumber,remainderNumber,courseStatus,`courseDuration`)" 
+ "VALUES(#{courseId}, #{startTime},#{coursePoint}, #{maxBabys}, #{signedNumber}, #{remainderNumber}, #{courseStatus}, #{courseDuration})") 
	@Options(useGeneratedKeys=true)
	int save(CourseTime ct);
	
	@Insert("<script>" + 
			"INSERT INTO tb_course_time(courseId, startTime,coursePoint,maxBabys,courseDuration,signedNumber,remainderNumber,courseStatus) values"+
			" <foreach collection=\"list\" item=\"item\" index=\"index\" separator=\",\" >  " + 
			" (#{item.courseId},#{item.startTime},#{item.coursePoint},#{item.maxBabys},#{item.courseDuration},#{item.signedNumber},#{item.remainderNumber},#{item.courseStatus})" + 
			" </foreach>  "+ 
			"</script>")
	int batchSave(List<CourseTime> list);

	@Delete("DELETE FROM  tb_course_time WHERE id=#{id}")
	int remove(Long id);
	
	@Delete("DELETE FROM  tb_course_time WHERE courseId=#{courseId}")
	int removeByCourseId(Long tb_course_time);

	@Select("select * from tb_course_time where courseId = #{courseId}")
	List<CourseTime> listTimeByCourseId(Long courseId);
	
	@Update("<script>"+ 
			"update tb_course_time " + 
					"<set>" + 
		            "<if test=\"id != null\">`id` = #{id}, </if>" + 
                    "<if test=\"courseId != null\">`courseId` = #{courseId}, </if>" + 
                    "<if test=\"startTime != null\">`startTime` = #{startTime}, </if>" + 
                    "<if test=\"coursePoint != null\">`coursePoint` = #{coursePoint}, </if>" + 
                    "<if test=\"maxBabys != null\">`maxBabys` = #{maxBabys}, </if>" + 
                    "<if test=\"signedNumber != null\">`signedNumber` = #{signedNumber}, </if>" + 
                    "<if test=\"remainderNumber != null\">`remainderNumber` = #{remainderNumber}, </if>" +  
                    "<if test=\"courseStatus != null\">`courseStatus` = #{courseStatus}, </if>" +  
                    "<if test=\"courseDuration != null\">`courseDuration` = #{courseDuration}, </if>" + 
          					"</set>" + 
					"where id = #{id}"+
			"</script>")
	int update(CourseTime bComments);
}
